package org.edu.modules.jxzy.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.edu.common.api.vo.Result;
import org.edu.common.aspect.annotation.AutoLog;
import org.edu.common.system.base.controller.BaseController;
import org.edu.common.system.query.QueryGenerator;
import org.edu.common.system.vo.LoginUser;
import org.edu.modules.jxzy.api.TestSysBaseApi;
import org.edu.modules.jxzy.api.TestSystemApi;
import org.edu.modules.jxzy.entity.JwCangku;
import org.edu.modules.jxzy.service.IJwCangkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
* @Description: 教材仓库表
* @Author: jeecg-boot
* @Date:   2021-04-14
* @Version: V1.0
*/
@Api(tags="教材仓库表")
@RestController
@RequestMapping("/jxzy")
@Slf4j
public class TestBaseController extends BaseController<JwCangku, IJwCangkuService> {

   @Autowired
   private TestSysBaseApi sysBaseApi;
    @Autowired
    private TestSystemApi systemApi;


   String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MjEyMzg2NzksInVzZXJuYW1lIjoiYWRtaW4ifQ.ySSyhB8fT-I4FjTmhA8qLWYILyOrufe1THbl5Y3jbzI";

    //获取所有班级信息
    @PostMapping("/edu-teach/teach/veBaseBanji/list")
    Result<?> queryBanjiList(){
        Result<?>  result;
        try{
            result=sysBaseApi.queryBanjiList(token);
        }catch(Exception e){
            systemApi();
            result=sysBaseApi.queryBanjiList(token);
        }


        return result;
    }


    //获取所有校区信息
//    @GetMapping("/edu-teach/teach/veBaseBanji/list")
    Result<?> systemApi(){
        LoginUser user=new LoginUser();
        user.setUsername("admin");
        user.setPassword("123456");
        Result<JSONObject> result=systemApi.sLogin(user);

        token= result.getResult().getString("token");
        log.info(token);
        return Result.OK();
    }
}
